package com.eas.ereceipt.adapter;

import java.util.ArrayList;

import com.eas.ereceipt.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DateAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private ArrayList<DateItem> items;
	
	public DateAdapter(Context c){
		inflater = LayoutInflater.from(c);
		gennerateItems();
	}
	
	private void gennerateItems(){
		items = new ArrayList<DateAdapter.DateItem>();
		
		DateItem item;
		
		item = new DateItem();
		item.setType("DAY");
		item.setValue("January 3, 2014");
		items.add(item);
		
		item = new DateItem();
		item.setType("WEEK");
		item.setValue("January 3-10, 2014");
		items.add(item);
		
		item = new DateItem();
		item.setType("MONTH");
		item.setValue("January, 2014");
		items.add(item);
		
		item = new DateItem();
		item.setType("YEAR");
		item.setValue("2014");
		items.add(item);
		
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = inflater.inflate(R.layout.row_date_spinner_selected_item, parent, false);
		TextView tvValue = (TextView) convertView.findViewById(R.id.tvValue);
		tvValue.setText(items.get(position).getValue());
		return convertView;
	}
	
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		convertView = inflater.inflate(R.layout.row_date_spinner_dropdown, parent, false);
		
		TextView tvTitle = (TextView) convertView.findViewById(R.id.tvTypeTitle);
		TextView tvValue  = (TextView) convertView.findViewById(R.id.tvValue);
		
		tvTitle.setText(items.get(position).getType());
		tvValue.setText(items.get(position).getValue());
		
		return convertView;
	}
	
	class DateItem{
		
		private String type;
		private String value;
		
		public String getType() {
			return type;
		}
		public void setType(String type) {
			this.type = type;
		}
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
	}

}
